package cn.xkai.exercise.c;

/**
 * @description: 猜数字大小
 * @author: kaixiang
 * @date: 2022-07-29
 **/
public class Solution114 {
    public static int guessNumber(int n) {
        int left = 1, right = n, mid = -1;
        while (left <= right) {
            mid = (left + right) >>> 1;
            if (guess(mid) == -1) {
                right = mid - 1;
            } else if (guess(mid) == 1) {
                left = mid + 1;
            } else {
                break;
            }
        }
        return mid;
    }

    public static int guess(int num) {
        int cur = 6;
        return Integer.compare(num, cur);
    }
}
